package com.study.manage.dal;

import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.study.manage.domain.BlogComment;
import com.study.manage.domain.enumm.LiveDieState;

public interface BlogCommentRepository extends PagingAndSortingRepository<BlogComment, Long> {

    int countByBlogIdAndState(Long blogId, LiveDieState state);

    @Query("select count(1) from BlogComment t,Blog b,EvaluateApply ea where t.blogId=b.id and b.type=6"
            + " and b.extId=ea.id and ea.evaluateId in (:evaluateIds) and t.userId=:userId "
            + " and t.state=:state and (DATE_FORMAT(t.createdAt, '%Y%m') = DATE_FORMAT(:date, '%Y%m'))")
    int countByUserIdAndStateAndMoth(@Param("evaluateIds") List<Long> evaluateIds,
            @Param("userId") Long userId, @Param("state") LiveDieState state,
            @Param("date") Date date);

    @Query("select t from BlogComment t,Blog b,EvaluateApply ea where t.blogId=b.id and b.type=6"
            + " and b.extId=ea.id and ea.evaluateId in (:evaluateIds) and t.userId=:userId and t.state=:state and (DATE_FORMAT(t.createdAt, '%Y%m') = DATE_FORMAT(:date, '%Y%m'))")
    Page<BlogComment> findByUserIdAndStateAndMoth(@Param("evaluateIds") List<Long> evaluateIds,
            @Param("userId") Long userId, @Param("state") LiveDieState state,
            @Param("date") Date date, Pageable pageable);
}
